package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.db.Settings;
import com.tanhua.dubbo.mapper.SettingsMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @version 1.0
 * @author： xtr
 * @date： 2021-03-07 19:11
 */
@Service
public class SettingsApiImpl implements SettingsApi {
    @Autowired
    private SettingsMapper settingsMapper;
    /**
     * 根据id查询用户通知设置
     *
     * @param userId
     * @return
     */
    @Override
    public Settings getSettingsById(Long userId) {
        //不能直接按照id查询，不然查询的是settings表的主键id查找的
        QueryWrapper<Settings> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        return settingsMapper.selectOne(queryWrapper);
    }

    /**
     * 更新用户通知设置
     *
     * @param settings
     */
    @Override
    public void updateSettings(Settings settings) {
        settingsMapper.updateById(settings);
    }

    /**
     * 新增用户通知信息
     *
     * @param settings
     */
    @Override
    public void saveSettings(Settings settings) {
        settingsMapper.insert(settings);
    }
}
